---
title: R语言处理CCK8或MTT数据，一步绘制生长曲线
author: Song Ou-Yang
date: '2021-08-14'
slug: r-cck8-mtt
categories: []
tags: [R]
subtitle: ''
summary: ''
authors: []
lastmod: '2021-08-14T18:13:28+08:00'
featured: no
image:
  caption: ''
  focal_point: ''
  preview_only: no
projects: []
---



<p>CCK8数据主要是统计OD450的吸收值，一般的数据形式如下，保存为<code>csv</code>格式</p>
<table>
<thead>
<tr class="header">
<th>Time</th>
<th>NC</th>
<th>NC</th>
<th>NC</th>
<th>OE</th>
<th>OE</th>
<th>OE</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>day1</td>
<td>0.549070969</td>
<td>0.549570976</td>
<td>0.547750963</td>
<td>0.543670962</td>
<td>0.536370963</td>
<td>0.545970956</td>
</tr>
<tr class="even">
<td>day2</td>
<td>0.675742972</td>
<td>0.696628983</td>
<td>0.690574949</td>
<td>0.637390961</td>
<td>0.630422963</td>
<td>0.653620952</td>
</tr>
<tr class="odd">
<td>day3</td>
<td>0.894142977</td>
<td>0.884125994</td>
<td>0.882670941</td>
<td>0.82057096</td>
<td>0.803780962</td>
<td>0.819401947</td>
</tr>
<tr class="even">
<td>day4</td>
<td>1.179670983</td>
<td>1.18457301</td>
<td>1.178542929</td>
<td>1.074040958</td>
<td>1.067993961</td>
<td>1.052209937</td>
</tr>
<tr class="odd">
<td>day5</td>
<td>1.505662991</td>
<td>1.507610027</td>
<td>1.500910915</td>
<td>1.387150955</td>
<td>1.32420196</td>
<td>1.389946927</td>
</tr>
</tbody>
</table>
<div id="首先我们要进行数据的预处理把短数据转换为长数据然后用ggpubr一步作图" class="section level2">
<h2>首先我们要进行数据的预处理,把短数据转换为长数据,然后用ggpubr一步作图</h2>
<pre class="r"><code>cck8 &lt;- read.csv(&quot;~/Desktop/cck8.csv&quot;) 
## 宽数据转换为长数据
library(reshape2) 
cck8_long&lt;-melt(cck8,
                 id.vars = c(&#39;Time&#39;),
                 variable.name=&#39;Sample&#39;,
                 value.name=&#39;OD450&#39;)
## 新增一个分组
cck8_long$Group=rep(c(&#39;control&#39;, &#39;treat&#39;), each = 15)  ##分为两组，每组15个数据
### 使用ggpubr画图，可以使用prism主题
library(ggpubr)</code></pre>
<pre><code>## 载入需要的程辑包：ggplot2</code></pre>
<pre class="r"><code>library(ggprism)
ggline(cck8_long, x = &quot;Time&quot;, y = &quot;OD450&quot;, 
       color = &quot;Group&quot;,shape=&#39;Group&#39;, 
       add = &quot;mean_sd&quot;,ylab = &quot;OD450 value&quot;,
       ggtheme = theme_prism(base_size = 12))</code></pre>
<p><img src="{{< blogdown/postref >}}index.en_files/figure-html/unnamed-chunk-1-1.png" width="672" /></p>
<div id="加个p值调整坐标适当美化" class="section level4">
<h4>加个P值，调整坐标，适当美化</h4>
<ul>
<li>首先预统计看下结果,记得统计方法一定是’anova’,而不是’t.test’</li>
</ul>
<pre class="r"><code>compare_means(OD450~Group, data=cck8_long, group.by = &quot;Time&quot;,method = &#39;anova&#39;)</code></pre>
<pre><code>## # A tibble: 5 x 7
##   Time  .y.           p   p.adj p.format p.signif method
##   &lt;chr&gt; &lt;chr&gt;     &lt;dbl&gt;   &lt;dbl&gt; &lt;chr&gt;    &lt;chr&gt;    &lt;chr&gt; 
## 1 day1  OD450 0.0823    0.082   0.08228  ns       Anova 
## 2 day2  OD450 0.00701   0.014   0.00701  **       Anova 
## 3 day3  OD450 0.000371  0.0015  0.00037  ***      Anova 
## 4 day4  OD450 0.0000675 0.00034 6.7e-05  ****     Anova 
## 5 day5  OD450 0.00309   0.0093  0.00309  **       Anova</code></pre>
<ul>
<li>结果还不错，接着添加显著标志,改色lancet配色</li>
</ul>
<pre class="r"><code>ggline(cck8_long, x = &quot;Time&quot;, y = &quot;OD450&quot;, 
       color = &quot;Group&quot;,shape=&#39;Group&#39;, title = &#39;xxx cell&#39;,
       add = &quot;mean_sd&quot;, palette = &#39;lancet&#39;,ylab = &quot;OD450 value&quot;,legend = c(0.1,0.9),
       ggtheme = theme_prism(base_size = 12))+stat_compare_means(label = &quot;p.signif&quot;,
                                                                 aes(group=Group),
                     method = &quot;anova&quot;,  
                     hide.ns = TRUE)</code></pre>
<p><img src="{{< blogdown/postref >}}index.en_files/figure-html/unnamed-chunk-3-1.png" width="672" />
- 可以调的细节还有很多,比如换个背景</p>
<pre class="r"><code>ggline(cck8_long, x = &quot;Time&quot;, y = &quot;OD450&quot;, 
       color = &quot;Group&quot;,shape=&#39;Group&#39;, title = &#39;xxx cell&#39;,
       add = &quot;mean_sd&quot;, palette = &#39;lancet&#39;,ylab = &quot;OD450 value&quot;,legend = c(0.1,0.8),
       ggtheme = theme_bw(base_size = 12))+stat_compare_means(label = &quot;p.signif&quot;,
                                                                 aes(group=Group),
                     method = &quot;anova&quot;,  
                     hide.ns = TRUE)</code></pre>
<p><img src="{{< blogdown/postref >}}index.en_files/figure-html/unnamed-chunk-4-1.png" width="672" />
细节地方AI处理一下,当然如果你安装了<code>esquisse</code>，你也可以直接导出成PPT</p>
<pre class="r"><code>esquisse:::ggplot_to_ppt()</code></pre>
<pre><code>## 载入需要的名字空间：rvg</code></pre>
<pre><code>## No ggplot object in environment...</code></pre>
</div>
</div>
